package Collections;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;


public class demo01 {
    public static void main(String[] args) {
//        ArrayList<String> list = new ArrayList<>();
//        Collections.addAll(list,"a","b","c");
//        System.out.println(list);
//        Collections.shuffle(list);
//        System.out.println(list);
//
//        Collections.sort(list);
//        System.out.println(list);

        ArrayList<Stu> stu = new ArrayList<>();

        stu.add(new Stu("jack",18));
        stu.add(new Stu("parker",19));
        stu.add(new Stu("jji",20));
        stu.add(new Stu("peter",18));

        //要重写tostring方法才能打印
        System.out.println(stu);
//        Collections.sort(stu);
//        System.out.println(stu);
        Collections.sort(stu, new Comparator<Stu>() {
            @Override
            public int compare(Stu o1, Stu o2) {
                return o1.getAge() - o2.getAge();
            }
        });

        System.out.println(stu);

    }
}
